/*
* INSANE - Interactive Structural Analysis Environment
*
* Copyright (C) 2003-2005
* Universidade Federal de Minas Gerais
* Escola de Engenharia
* Departamento de Engenharia de Estruturas
* 
* Author's email :    insane@dees.ufmg.br
* Author's website :  http://www.dees.ufmg.br/insane
* 
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or any later version.
* 
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
* 
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
*/
package br.ufmg.dees.insane.model.disc.analysismodel;

import br.ufmg.dees.insane.crossSection.CrossSection;
import br.ufmg.dees.insane.materialMedia.material.Material;
import br.ufmg.dees.insane.model.disc.element.FrameElement;
import br.ufmg.dees.insane.model.disc.fem.FemModel;
import br.ufmg.dees.insane.util.IMatrix;
import br.ufmg.dees.insane.util.IVector;

/**
*A class representing an analysis model of a FrameElement.
*
*@author Fonseca, Flavio & Pitangueira, Roque
*@version 1.0
*@since September 2003
*@see model.discrete.element.FrameElement
*/

public abstract class FrameElmAnalysis extends AnalysisModel implements java.io.Serializable {
	
//********************************************************************************
	
	/** Returns the type of the Shape adequate to the type of AnalysisModel.
	*@return The type of the Shape adequate to the type of AnalysisModel.
	*/
	public abstract String getDefaultShapeType();
	
	/** Returns the nodal rotation matrix of the specified FrameElement, accordingly to this AnalysisModel type.
	*@param elm The FrameElement whose nodal rotation matrix is desired.
	*@return The nodal rotation matrix of the specified FrameElement, accordingly to this AnalysisModel type.
	*/
	public abstract IMatrix nodalRotationMatrix(FrameElement elm);
	
	/** Returns the local stiffness matrix of the specified FrameElement, accordingly to its AnalysisModel type.<br>
	*This matrix does not consider the possible liberations at the extremities of the FrameElement.
	*@param elm The FrameElement whose local stiffness matrix is desired.
	*@return The local stiffness matrix of the specified FrameElement, accordingly to its AnalysisModel type.
	*/
	public abstract IMatrix localStiffnessMatrix(FrameElement elm);
	
	/** Returns the corrected local stiffness matrix of the specified FrameElement, accordingly to its AnalysisModel type.
	*This matrix is corrected to consider the liberations at the extremities of the FrameElement.
	*@param elm The FrameElement whose corrected local stiffness matrix is desired.
	*@return The corrected local stiffness matrix of the specified FrameElement, accordingly to its AnalysisModel type.
	*/
	public abstract IMatrix localCorrectedStiffnessMatrix(FrameElement elm);
	
	/** Returns the transformation matrix of the specified FrameElement, accordingly to its AnalysisModel type.
	*@param elm The FrameElement whose transformation matrix is desired.
	*@return The transformation matrix of the specified FrameElement, accordingly to its AnalysisModel type.
	*/
	public abstract IMatrix transformationMatrix(FrameElement elm);
	
	/** Returns the local equivalent nodal force vector of the specified FrameElement, accordingly to the AnalysisModel type.
	*This vector does not consider the possible liberations at the extremities of the FrameElement.
	*@param elm The FrameElement whose local equivalent nodal force vector is desired.
	*@return The local equivalent nodal force vector of the specified FrameElement, accordingly to the AnalysisModel type.
	*/
	public abstract IVector localEquivalentForceVector(FrameElement elm);
	
	/** Returns the corrected local equivalent nodal force vector of the specified FrameElement, accordingly to the AnalysisModel type.
	*This matrix is corrected to consider the liberations at the extremities of the FrameElement.
	*@param elm The FrameElement whose corrected local equivalent nodal force vector is desired.
	*@return The corrected local equivalent nodal force vector of the specified FrameElement, accordingly to the AnalysisModel type.
	*/
	public abstract IVector localCorrectedEquivalentForceVector(FrameElement elm);
	
//********************************************************************************
	
	/** Prints in the screen a table with the valid nodal displacements for the AnalysisModel type.
	*@param mod The FemModel which contains the data to be printed.
	*/
	public abstract void printDisplacements(FemModel mod);
	
	/** Prints in the screen a table with the valid actions at elements' extremities for the AnalysisModel type.
	*@param mod The FemModel which contains the data to be printed.
	*/
	public abstract void printActionsAtExtremities(FemModel mod);
	
	/** Prints in the screen a table with the valid support reactions for the AnalysisModel type.
	*@param mod The Model which contains the data to be printed.
	*/
	public abstract void printReactions(FemModel mod);
	
//********************************************************************************
	
	/** Returns the B matrix related to analysis model type 
	*@param dl The matrix containing local derivates of shape functions.
	*@param n The vector containing shape functions in natural coordinates.
	*@param cN The matrix containing nodal coordinates in cartesian system.
	*@return The matrix B 
	*/
	public IMatrix mountBMatrix(IMatrix dl, IVector n, IMatrix cN) {
		
		int nNos = dl.getNumCol();
		IMatrix invertJacobian;
		IMatrix dG = new IMatrix(2,dl.getNumCol());
		IMatrix b = new IMatrix(3,(2*nNos));
		dG.setZero();
		b.setZero();
		
		invertJacobian = this.invertJacobian(this.getJacobian(dl, cN));
		dG.mul(invertJacobian,dl);
		
		for(int i=0; i<nNos; i++) 
		{
			b.setElement(0,(2*i),dG.getElement(0,i));
			b.setElement(1,((2*i)+1),dG.getElement(1,i));
			b.setElement(2,(2*i),dG.getElement(1,i));
			b.setElement(2,((2*i)+1),dG.getElement(0,i));
		}
			return(b);};
	
//********************************************************************************
           
            /** Returns the B matrix related to analysis model type 
                *@param dg The vector containing global derivates of shape functions.
                *@return The matrix B 
                */
                public IMatrix mountBMatrix(IVector dg) { return null; }
                
//********************************************************************************
	
	/** Mounts the matrix of the material properties for the analysis model type.
	*@param a The matrix of material properties.
	*@return matrix D related to analysis model type 
	*/
	public IMatrix mountDMatrix(double[][] a) {
		IMatrix b = new IMatrix(1,1);
		b.setElement(1, 1, a[0][0]);
		return b;
	};

//  ********************************************************************************

    /** Mounts the matrix of the material properties for the analysis model type.
    *@param a The matrix of material properties.
    *@return matrix D related to analysis model type 
    */
    public IMatrix mountDMatrix(double[][] a, CrossSection cs) {
        return null;
    };
	
//********************************************************************************
	
	/** Return the inverse of jacobian matrix.
	*@param a The jacobian matrix.
	*@return the inverse of jacobian matrix.
	*/
	protected IMatrix invertJacobian(IMatrix a) {return null;};
	
//********************************************************************************
	
	/** Return the jacobian matrix.
	*@param dl The matrix of local derivates.
	*@param cN The matrix of nodal coordinates.
	*@return dl * cN The jacobian matrix.
	*/
	public IMatrix getJacobian(IMatrix dl, IMatrix cN){return null;};
	
//********************************************************************************
	
	/** Return the number of active stresses according to this Analysis model type.*/
	public int getNumberOfActiveStress(){return 1;};
	
//********************************************************************************
	
	/** Return the number of active strains according to this Analysis model type.*/
	public int getNumberOfActiveStrains(){return 1;};
	
//********************************************************************************
	
	/** Return the non zero stresses that perform in one point. 
	*@param a The IVector containing stresses of the point.
	*@param b The Material that will be used to obtain material properties.
	*@return stressVector The IVector according this Analysis Model.
	*/
	public IVector getStressVector(IVector a, Material b){
		IVector c = new IVector(1);
		c.setElement(0, a.getElement(0));
		return c;
	};
	
//********************************************************************************
	
	/** Return the non zero strains that perform in one point. 
	*@param a The IVector containing strains of the point.
	*@param b The Material that will be used to obtain material properties.
	*@return strainVector The IVector according this Analysis Model.
	*/
	public IVector getStrainVector(IVector a, Material b){
		IVector c = new IVector(1);
		c.setElement(0, a.getElement(0));
		return c;
	};
	
//********************************************************************************
	
	/** Return the String representing the non zero stresses of this Analysis Model.
	*@return The string containing the label of non zero stresses of this Analysis Model.
	*/
	public String getStressLabels(){
		return "sigmaXX";
	};
	
//********************************************************************************
	
	/** Return the string representing the non zero strains of thisAnalysis Model.
	*@return The string containing the label of non zero strains of this Analysis Model.
	*/
	public String getStrainLabels(){
		return "epsilonXX";
	};
	
//********************************************************************************
	
	/** Return the integration factor according to analysis model type.
	*@param n The vector containing the shape functions.
	*@param cN The matrix containing the nodal coordinates in cartesian system.
	*@return The integration factor according to analysis model type.
	*/
	public double getStiffnessFactor(IVector n, IMatrix cN){return 1;};
	
//********************************************************************************
}
